<template>
  <div>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="日期">
                <a-date-picker :allowClear="true" ref="datePicker" @change="datePickerChange"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button
                  type="primary"
                  @click="$refs.table.refresh(true)"
                >查询</a-button>
                <a-button style="margin-left: 8px" @click="handleReset">重置</a-button>
                <a-button style="margin-left: 8px" @click="handleExport">导出</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :scroll="{ x: 1300 }"
        :data="loadData"
        showPagination="auto"
      >
      </s-table>
    </a-card>
  </div>
</template>

<script>
  import { STable } from '@/components'
  import PartnersForm from '@/views/proxy/partner/Form'
  import { getDailyReportStatistics } from '@/api/finance'
  import { formatAmount } from '@/utils/util'

  export default {
    name: 'List',
    components: {
      PartnersForm,
      STable
    },
    data () {
      return {
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: 'id'
          },
          {
            title: '时间',
            dataIndex: 'date'
          },
          {
            title: '订单总数',
            dataIndex: 'number_of_order'
          },
          {
            title: '订单总金额',
            customRender: item => formatAmount(item.total_amount_of_orders)
          },
          {
            title: '充值总金额',
            customRender: item => formatAmount(item.total_recharge_amount)
          },
          {
            title: '新增代理数',
            dataIndex: 'total_number_of_new_agents'
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return getDailyReportStatistics(Object.assign(parameter, this.queryParam))
        }
      }
    },
    created () {

    },
    methods: {
      handleReset () {
        this.queryParam = {}
        this.$refs.datePicker.$refs.picker.clearSelection(new MouseEvent('click'))
      },
      datePickerChange (moment, date) {
        this.queryParam.date = date
      },
      handleExport () {
        getDailyReportStatistics(Object.assign({ export: true }, this.queryParam))
      }
    }
  }
</script>
